/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TreeTestApplet.java
 *
 * Created on Aug 5, 2009, 3:28:10 PM
 */
package GeneralTesting;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;

/**
 *
 * @author Heather
 */
public class TreeTestApplet extends javax.swing.JApplet
{

  /** Initializes the applet TreeTestApplet */
  public void init()
  {
    try
    {
      java.awt.EventQueue.invokeAndWait(new Runnable()
      {

        public void run()
        {
          initComponents();
        }
      });
    } catch (Exception ex)
    {
      ex.printStackTrace();
    }
  }

  /** This method is called from within the init() method to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jScrollPane1 = new javax.swing.JScrollPane();
    theTree = new javax.swing.JTree();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();

    theTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
      public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
        theTreeValueChanged(evt);
      }
    });
    jScrollPane1.setViewportView(theTree);

    jButton1.setText("print selected rows");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });

    jButton2.setText("blank and replace");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGap(19, 19, 19)
        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 307, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addGap(18, 18, 18)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
          .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE))
        .addContainerGap())
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE))
          .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 399, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addContainerGap(62, Short.MAX_VALUE))
    );
  }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
      // TODO add your handling code here:
      TreePath[] selectedPaths = theTree.getSelectionPaths();

      for (int i = 0; i < selectedPaths.length; i++)
      {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)selectedPaths[i].getLastPathComponent();
        System.out.println((String)selectedNode.getUserObject());
      }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void theTreeValueChanged(javax.swing.event.TreeSelectionEvent evt)//GEN-FIRST:event_theTreeValueChanged
    {//GEN-HEADEREND:event_theTreeValueChanged
      // TODO add your handling code here:
      DefaultMutableTreeNode selected = (DefaultMutableTreeNode) theTree.getLastSelectedPathComponent();


      System.out.println((String)selected.getUserObject());
    }//GEN-LAST:event_theTreeValueChanged

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
    {//GEN-HEADEREND:event_jButton2ActionPerformed
      // TODO add your handling code here:

      ((DefaultMutableTreeNode)theTree.getModel().getRoot()).removeAllChildren();
      ((DefaultMutableTreeNode)theTree.getModel().getRoot()).add(new DefaultMutableTreeNode("STUPID FREAK'N TREE"));

      theTree.updateUI();


    }//GEN-LAST:event_jButton2ActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JTree theTree;
  // End of variables declaration//GEN-END:variables
}
